#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>

int gval = 10;
int main()
{
    

      printf("父进程开始运行,pid:%d\n",getpid());
      int n = fork();
      while(1)
      {

      if(n == 0)
      {
          sleep(4);
          gval += 10;
          printf("子进程，pid:%d\n修改gval%d->%d",getpid(),gval,gval+10);
          sleep(1);
      }

      else
      {     
          printf("我是父进程，pid:%d\n查看gval:%d",getpid(),gval); 
          sleep(1);
      }
      }



//    printf("父进程开始运行,pid:%d\n",getpid());
//    fork();
//    printf("进程开始运行,pid:%d\n",getpid());
//



    //while(1)
    //{
    //    printf("我是一个进程,PID:%d,父进程PPID:%d\n",getpid(),getppid());
    //    sleep(1);
    //}






    //chdir("/home/wxd");
    //FILE* pf = fopen("new_file.txt","a");
    // 
    //if(pf == NULL)
    //{
    //    perror("fopen");
    //    return 1;
    //}
    //int n = 10;
    //while(n--)
    //{
    //    fprintf(pf,"Hello Linux!\n");
    //}

    //fclose(pf);

    //while(1)
    //{
    //    printf("我是一个进程，我的pid:%d\n",getpid());
    //    sleep(1);
    //}
    return 0;
}
